<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh" xml:lang="zh">
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>
      <?php echo $title?>
    </title>
    <link rel="stylesheet" type="text/css" href="/Content/style/result.css" />
    <link rel="stylesheet" type="text/css" href="/Content/style/polls.css" />
    <script type="text/javascript" src="/Content/scripts/jquery-1.4.4.min.js"></script>
    
    <script type="text/javascript">
    var id = <?php echo $activity["Id"]?>;
    var count_votes = <?php echo $countVotes?>;
    function showAddCmt(){
        var cmtsAdd = $('#cmtsAdd');
        var cmtAddArrow = $('#cmtAddArrow');
        if(cmtsAdd.css("display")=="none")
        {
        	cmtsAdd.slideDown(250);
        	cmtAddArrow.text("收起评论");
        }
        else
        {
        	cmtsAdd.slideUp(250);
        	cmtAddArrow.text("添加评论");
        }
    }
    function check(obj){
    	if($(obj).children("div").attr("class")=="pok")
        {
    		$(obj).children("div").attr("class","pn");
        }
        else
        {
        	$(obj).children("div").attr("class","pok");
        }
    }
	function submit_vote(){
		var voteData = 0;
		var q = 1;
		for (var i=0;i<count_votes;i++)
		{
			var checkbox = $("#cb_"+i);
			var ischeck = checkbox.ischeck();
			voteData += ischeck * q;
			q*=2;
		}
		var name = $("#pname").val();
		if (name == '')
		{
			alert("请输入您的姓名");
			return;
		}
		$.ajax({
            type:'post',
            url:"/lib/ajax/submitVote.php",
            data:{name:name,voteData:voteData,countVotes:count_votes,id:id},
            success:
    function(data){
            $("#poll_tb tr:last-child").hide();
            $("#poll_tb").append(data);
            $("#save").hide();
            $("#pname").val("");
                }
            });
		
	}

	$.fn.ischeck = function() {
		if($(this).attr("class")=="pok")
        {
    		return 1;
        }
        else
        {
        	return 0;
        }
	};
	
    function submitComment(){
        var cmtator = $('#username').val();
        if(cmtator=='')
        {
			alert("请留下您的尊姓大名");
			return;
        }
        var comment = $('#newCmt').val();
        $.ajax({
                        type:'post',
                        url:"/lib/ajax/submitComment.php",
                        data:{cmtator:cmtator,comment:comment,id:id},
                        success:
                function(data){
                        var obj = eval('('+data+')');
                        $('#cmts').append(
                                $("<div class='cmt' />")
                                	.append($("<div class='cmtAvatar' />")
                                		.append("<div class='avatarSmall' />"))
                                	.append("<div class='cmtCmt'>"+obj.comment+"</div>")
                                	.append(
                                        $("<div class=cmtDetails />")
                                    	.append("<div>"+obj.time+"</div>")
                                    	.append("<span>|</span>")
                                    	.append("<div>"+obj.cmtator+"</div>")));
                        $('#username').val("");
                        $('#newCmt').val("");
                        showAddCmt();
                }
        });
    }

    function cal_votedate()
    {
        var votes = new Array(count_votes);
        $("tr.participant").each(
			function()
			{
				for (var i=0;i<count_votes;i++)
				{
					var check = $(this).children("div").ischeck();
					votes[i] += check;
				}
			}
        );
    	
    }	
    </script>
  </head>
  <body onload="cal_votedate()">
   
    <div id="background"></div>
    <div id="container">
      <div id="page">
        <div id="banner"></div><br />
        <div id="doodleshadow">
          
          <div id="doodlecontainer">
            <div id="doodle">
              <div id="header" class="fixedContent clearfix">
                <div id="logo">
                  <a href="#"><img class="logo" src=
                  "/Content/images/images.png" width="200" height="100" alt=
                  "Have a good time" /></a>
                </div>
              </div>
              <div id="content" style="">
                <div id="anonymousHeader" class="contentPart" style="">
                  <div id="anonymousMessage">
                    <h2 class="blue spaceCBefore" style="padding-bottom: 5px;">
                      一起…寻找…我们的最佳约会时间……
                    </h2>
                    <h4 class="green">
                      请在文本框中输入你的名字并选择您的空闲时间
                    </h4>
                  </div>
                </div>
                <div id="pollHeader" class="contentPart" style="">
                  <div class="clearfix fixedContent">
                    <div id="pollInfos">
                      <h2 class="red" id="pollTitle">
                        <?php
                        echo $title?>
                      </h2>
                      <div id="pollDetails" class="grey clearfix spaceEAfter">
                        <p>
                          	由<?php echo $createrName?>发起这个活动
                        </p><span>|</span>
                        <div id="noPart" title="0 participants">
                          <div class="icon partIcon"></div>
                          <span id="countParticipants"><?php
                          echo $countParticipants?></span>
                        </div><span>|</span>
                        <div id="noCmt" title="0 评论">
                          <div class="icon commentIcon"></div><span id=
                          "countComments"><?php
                          echo $countComments?></span>
                        </div><span>|</span>
                        <div id="latestActivity" title="最近的活动">
                          <div class="icon timeIcon"></div><span id=
                          "lastActivity"><?php
                          echo $startTime?></span>
                        </div>
                      </div>
                      <div id="pollDescription" class="spaceCBefore">
                        <?php
                        echo $pollDescription?>
                      </div>
                    </div>
                  </div>
                </div>
                <div id="pollArea" class="contentPart" style="">
                  
                    <div id="ptContainer">
                      <table cellspacing="0" cellpadding="0" class="poll" id="poll_tb" summary="787">
                        <tbody>
                          <tr class="header date day">
                            <th class="nonHeader"></th>
                            <?php 
                                foreach ($votes as $vote)
                                {
                                    $option = $vote["Option"];
                                    $year = substr($option, 0, 4);
                                    $date = substr($option, 5, 5);
                                    echo '<th class="dsep">
                                          <p>
                                            '.$year.'
                                          </p>
                                          <p>
                                          	'.$date.'
                                          </p>
                                         </th>';
                                }
                            
                            ?>
                          </tr>
                          
                          <?php 
                              foreach ($votedatas as $votedata)
                              {
                                  echo '<tr class="participant">
                                  		<td class="pname long">
                                      		<div class="inlineEdit" style="display: none;">
                                      			<a class="inlineEditIcon "></a>
                                      			<a class="inlineDeleteIcon"></a>
                                      		</div>
                                      		<div class="pname" title="'.$votedata["Name"].'">
                                      			'.$votedata["Name"].'
                                      		</div>
                                  		</td>';
                                  $voteData = $votedata["VoteData"];
                                  for ($i = 0; $i < $countVotes; $i++) {
                                      if($voteData % 2)
                                      {
                                          echo '<td class="y" id="votedata_'.$i.'">
                                  					<div class="partTableCell pok"></div>
                                      			</td>';
                                      }
                                      else
                                      {
                                          echo '<td class="n" id="votedata_'.$i.'">
                                      				<div class="partTableCell pn"></div>
                                      			</td>';
                                      }
                                      $voteData /= 2;
                                  } 
                                echo "</tr>";
                              }
                          ?>
                          	
                          	
                          
                          <tr class="participation twoLevel partMyself">
                            <td class="pname">
                              <div style="width: 182px">
                                <input type="text" name="name" id="pname"
                                class="rescueData inputText hintText long"
                                maxlength="64" />
                              </div>
                            </td>
                            <?php 
                            $i = 0;
                            foreach ($votes as $vote)
                            {
                                echo '<td class="voteCheck" title="'.$vote["Option"].'">
                                      	<div onclick="check(this)">
                                      		<div id="cb_'.$i++.'" class="pok" ></div>
                                      	</div>
                            		  </td>';
                            }
                            ?>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                    <div id="belowTable" class="spaceDBefore spaceCAfter">
                      <button id="save" onclick="submit_vote()">保存</button>
                    </div>
                </div>
                <div id="calendarView" style="display: none;"></div>
                <div id="adminView" style="display: none;"></div>
                <div id="sponsoredLinks" class="infoBox yellowBG" style=
                "display: none;"></div>
                <div id="cmtsContainer" class="contentPart" style="">
                  <div id="cmtsPart" class="clearfix">
                    <div class="cmtsHeader">
                      <h3 id="cmtTitle">
                        评论
                      </h3>
                      <div class="cmtsLink fixedContent clearfix">
                        <a id="cmtAddArrow" class="submit" onclick=
                        "showAddCmt()">添加评论</a>
                      </div>
                      <div id="cmtsAdd" class="cmtsAdd" style="display: none;">
                        <div id="cmtatorAvatar" class="avatarSmall"></div>
                        <h5 id="nametitle">
                          您的姓名:
                        </h5><input type="text" name="username" id=
                        "username" />
                        <h5 id="commentTitle">
                          评论
                        </h5>
                        <div>
                          <textarea id="newCmt" name="comment" class=
                          "newCmt commentData rescueData">
</textarea> <span id="countCmt"></span>
                        </div>
                        <p id="formError" class="error" style="display: none;">
                        </p>
                        <div>
                          <button id="submitComment" class="submit" onclick=
                          "submitComment()">发表评论</button>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="bg2 comment_cont" id="cmts">
					<?php 
					foreach ($comments as $cmt)
					{
					    echo '<div class="cmt">
					        <div class="cmtAvatar">
					            <div class="avatarSmall"></div>
					        </div>
					        <div class="cmtCmt">'.$cmt["Content"].'</div>
					        <div class="cmtDetails">
					            <div>'.$cmt["Time"].'</div>
					            <span>|</span>
					            <div>'.$cmt["Name"].'</div>
					        </div>
					   </div>';
					}
					?>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>
